package com.example.fragment;

import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class TitleFragment extends Fragment{
	private Button button1;
	private Button button2;
	private Button button3;
	private Button button4;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		//System.out.println("onCreateView");
		View view=inflater.inflate(R.layout.fragment_title, container);
		button1=(Button) view.findViewById(R.id.button1);
		button2=(Button) view.findViewById(R.id.button2);
		button3=(Button) view.findViewById(R.id.button3);
		button4=(Button) view.findViewById(R.id.button4);
		
		button1.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				replaceFragment(new FirstFragment());
			}
		});
		
		button2.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				replaceFragment(new SecondFragment());
			}
		});
		
		button3.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				replaceFragment(new ThridFragment());
			}
		});
		
		button4.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View arg0) {
				// TODO Auto-generated method stub
				replaceFragment(new FourFragment());
			}
		});
		return view;
	}

	public void replaceFragment(Fragment fragment){
		FragmentManager fm=TitleFragment.this.getActivity().getSupportFragmentManager();
		FragmentTransaction ft=fm.beginTransaction();
		ft.replace(R.id.content, fragment);
		ft.commit();
	}

	
}
